import * as TYPES from '../actions/types';
import {NavigationActions} from "react-navigation";
import {AsyncStorage} from "react-native";

//用户未登录情况下的状态
const initialState = {
    isLoggedIn: false,
    user: {},
    status: null,
    info:null
};

export default function user(state=initialState, action){

    switch(action.type){

        case TYPES.LOGIN_START:
            console.info("正在执行 reducer...........................");
            return {
                ...state,
                status: 'doing',
            };

        case TYPES.LOGIN_IN:
            
            AsyncStorage.setItem("name","songdewu");
            AsyncStorage.getItem("name",function(err,ret){
                console.log(ret);
                console.log(err);
            });

            return {
                ...state,
                isLoggedIn: true,
                user: action.user,
                status: 'done',
                info:action.info
            };

        case TYPES.LOGIN_OUT:
            return {
                ...state,
                isLoggedIn: false,
                user: {},
                status: null,
                info:action.info
            };
        case TYPES.LOGIN_ERROR:
            return {
                ...state,
                isLoggedIn: false,
                user: {},
                status: 'error',
                info:action.info
            }
        
        case TYPES.ISLOGIN:

            return {
                ...state,
                isLoggedIn:true,
                user:{},
            }
            break;    

        default:
            return state;
    }

}